package edu.spec.lyq.week09.class2.home.work2.two;

import java.util.ArrayList;
import java.util.List;

/**
 * \* User: 11028
 * \* Date: 2018/10/27
 * \* Time: 16:54
 * \* Description:有如下Student 对象，
 *
 *  　 private String name;
 *
 *     private int age;
 *
 *     private int score;
 *
 *     private String classNum;
 *
 * 其中，classNum 表示学生的班号，例如“class05”。 有如下List List list = new ArrayList();
 *
 * list.add(new Student(“Tom”, 18, 100, “class05”));  	//参数第一个表示姓名，第二个是年龄，第三个是分数，第4个是班级
 *
 * list.add(new Student(“Jerry”, 22, 70, “class04”));
 *
 * list.add(new Student(“Owen”, 25, 90, “class05”));
 *
 * list.add(new Student(“Jim”, 30,80 , “class05”));
 *
 * list.add(new Student(“Steve”, 28, 66, “class06”));
 *
 * list.add(new Student(“Kevin”, 24, 100, “class04”));
 *
 * 在这个list 的基础上，完成下列要求：
 *
 * 1） 计算所有学生的平均年龄
 *
 * 2） 计算各个班级的平均分
 */
public class Student {
    private String name;

    private int age;

    private int score;

    private String classNum;

    public Student(String name, int age, int score, String classNum) {
        this.name = name;
        this.age = age;
        this.score = score;
        this.classNum = classNum;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public int getScore() {
        return score;
    }

    public String getClassNum() {
        return classNum;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public void setClassNum(String classNum) {
        this.classNum = classNum;
    }

    public static void main(String[] args) {
        int average = 0,averscore4=0,averscore5=0,averscore6=0,i4=0,i5=0,i6=0;

        List list = new ArrayList();
        list.add(new Student("Tom", 18, 100, "class05"));  	//参数第一个表示姓名，第二个是年龄，第三个是分数，第4个是班级

        list.add(new Student("Jerry", 22, 70, "class04"));

        list.add(new Student("Owen", 25, 90, "class05"));

        list.add(new Student("Jim", 30,80 , "class05"));

        list.add(new Student("Steve", 28, 66, "class06"));

        list.add(new Student("Kevin", 24, 100, "class04"));

        for(int i=0;i<list.size();i++)
        {
            Student s = (Student) list.get(i);
            average += s.getAge();
            if(s.getClassNum() == "class04") {
                averscore4 += s.getScore();
                i4++;
            }
            else if(s.getClassNum() == "class05") {
                averscore5 += s.getScore();
                i5++;
            }
            else {
                averscore6 += s.getScore();
                i6++;
            }

        }
        System.out.println("所有学生的平均年龄:"+average/list.size());
        System.out.println("4班的平均分:"+averscore4/i4);
        System.out.println("5班的平均分:"+averscore5/i5);
        System.out.println("6班的平均分:"+averscore6/i6);
    }
}
